package cn.yueranzs.login.common;

import lombok.Data;
import org.springframework.beans.BeanUtils;

/**
 * dto及数据的封装
 * @author yueranzs
 * @date 2021/12/14 16:29
 */
@Data
public class DataUtil {


    /**
     * dto转实体类 并获取数据
     * @param dto
     * @param tClass 实体类
     * @return
     */
    public static <T> T setData(Object dto,Class<T> tClass) {
        T instance = null;
        try {
            instance = tClass.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        assert instance != null;
        BeanUtils.copyProperties(dto,instance);
        return instance;
    }

}
